<?php
	namespace Qzn\Model;
	require_once('./Model/database.php');
	require_once('./Model/DBConfig.php');

	class MemberListHandler {
		private  $m_db = null;
		
		public function __construct (Database $db) {
			$this->m_db = $db;
		}
		
		/**
		 * Gets an array of usernames
		 * @return array $ml
		 */
		public function GetMemberList () {
			$ml =  DatabaseQuery::SelectMemberList($this->m_db);			
			
			return $ml;
		}

		/**
		 * Removes a member from db
		 * @param MemberListVIew $mlw
		 */
		public function RemoveMember(\Qzn\View\MemberListView $mlw, \Qzn\View\LoginView $lw) {
			if ($lw->GetUserCat() >= 3) {
				$user = $mlw->GetRemoveUser();
				
				if (isset($user)) {
					DatabaseQuery::RemoveMemberQuery($user, $this->m_db);
				}
			}
		}

		/**
		 * Promotes a member from db
		 * @param MemberListVIew $mlw
		 */
		public function PromoteMember(\Qzn\View\MemberListView $mlw, \Qzn\View\LoginView $lw) {
			if ($lw->GetUserCat() >= 3) {
				$user = $mlw->GetPromoteUser();
				
				if (isset($user)) {
					DatabaseQuery::PromoteMemberQuery($user, $this->m_db);
				}
			}
		}
		
		/**
		 * @param MemberListView $mlw
		 * @return string Testdata
		 */
		public function Test(MemberListView $mlw) {
			if ($this->RemoveMember("ratt")) {
				echo "hittar inte användaren.";
				return false;
			}
			
			return true;
		}
	}
?>